image: registry.gitlab.com/pages/hugo/hugo_extended:latest

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  DEPLOY_DIR: "/home/gitlab-runner/www/mivar"

stages:
  - test
  - build
  - deploy

test:
  tags:
    - iu5edu
  stage: test
  rules:
    - if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == $CI_DEFAULT_BRANCH
  before_script:
    - apk add --no-cache go curl bash nodejs npm
    - npm install postcss postcss-cli autoprefixer
  script:
    - npm install postcss-cli
    - hugo

site:
  tags:
    - iu5edu
  stage: build
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
  before_script:
    - apk add --no-cache go curl bash nodejs npm
    - npm install postcss postcss-cli autoprefixer
  script:
    - hugo
    - cp public/ru/404.html public/404.html
  artifacts:
    paths:
      - public

deploy:
  tags:
    - iu5edu-prod
  stage: deploy
  needs:
    - job: site
      artifacts: true
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  environment:
    name: production
  script:
    - rm -rf ${DEPLOY_DIR}/*
    - cp -r ./public/. ${DEPLOY_DIR}/.
  after_script:
    - rm -r ${CI_PROJECT_DIR}
